package com.zr.sms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.sms.model.Employee;

import net.sf.json.JSONObject;
/**
 * 验证旧密码功能
 * @author dyt
 *
 */
public class ValidateOldEpswServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		//设置字符编码为UTF-8
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		HttpSession   session = req.getSession();
		JSONObject jo=new JSONObject();
		PrintWriter  pw = resp.getWriter();
		
		String oldepsw=req.getParameter("oldepsw");
		session.setAttribute("oldepsw", oldepsw);
		//获取存储在session中的员工对象中的密码，ID
		Employee em=(Employee) session.getAttribute("currentemp");
		String epsw=em.getEpsw();
		//判断输入原密码是否和用户密码一致
		int eid=em.getEid();
		if (oldepsw.equals(epsw)){
			jo.put("msg",1);
			pw.write(jo.toString());
		}else {
			jo.put("msg",0);
			pw.write(jo.toString());
		} 
	}
}
